package com.ctshk.sapp.order.airexpress.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.rpc.order.airexpress.req.AirportExpressOrderRefundApprovalReq;
import com.ctshk.rpc.order.airexpress.service.IAirportExpressOrderRefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;

/**
 * <p>
 * 机场快线退款记录 前端控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-02-23
 */
@RestController
@RequestMapping("/airport/express/order/refund")
@Api(value = "机场快线订单退款", tags = "机场快线订单退款")
public class AirportExpressOrderRefundController extends BaseController {
    @DubboReference
    IAirportExpressOrderRefundService airportExpressOrderRefundService;

    @ApiOperation(value = "机场快线-订单操作-删除审批失败的退款记录", notes = "机场快线-订单操作-删除审批失败的退款记录")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.DELETE, operTitle = "机场快线-订单中心-删除审批失败的退款记录", operDesc = "机场快线-订单中心-删除审批失败的退款记录")
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Long id) {
        Long userId = getCurrentUser(getRequest()).getId();
        int num = airportExpressOrderRefundService.delete(id, userId);
        return Result.success(num);
    }

    @ApiOperation(value = "退款审核", notes = "退款审核")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "退款审核", operDesc = "退款审核")
    @PostMapping("/approval")
    public Result approval(@RequestBody @Valid AirportExpressOrderRefundApprovalReq req) {
        req.setUserId(getCurrentUser(getRequest()).getId());
        return airportExpressOrderRefundService.approval(req);
    }
}
